import { MockMethod } from 'vite-plugin-mock';
import { resultError, resultSuccess } from '../_util';

function createFakeUserList() {
  return [
    {
      userId: '1',
      username: 'vben',
      realName: 'Vben Admin',
      desc: 'manager',
      password: '123456',
      token: 'fakeToken1',
      roles: [
        {
          roleName: 'Super Admin',
          value: 'super',
        },
      ],
    },
    {
      userId: '2',
      username: 'test',
      password: '123456',
      realName: 'test user',
      desc: 'tester',
      token: 'fakeToken2',
      roles: [
        {
          roleName: 'Tester',
          value: 'test',
        },
      ],
    },
  ];
}

const fakeCodeList: any = {
  '1': ['1000', '3000', '5000'],

  '2': ['2000', '4000', '6000'],
};

const categoryList: any = [
  {
    "createTime":"2017-09-12 18:11:27",
    "creator":"admin",
    "updateTime":"2021-04-24 01:07:34",
    "updator":"0000001",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa5e758e5d015e75927af40005",
    "pid":"",
    "name":"大汉集团",
    "code":"222",
    "frontShow":1,
    "shortName":"MGJ",
    "note":"aaaaaaaaaaaaa",
    "orderNo":333,
    "companyId":"a8dc5e4887bc226e359b0350b16251bb",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2018-01-26 15:29:02",
    "creator":"admin",
    "updateTime":"2020-06-19 17:14:20",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa61213a5e0161315ea8340032",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"MPMS",
    "code":"117",
    "frontShow":null,
    "shortName":"MPMS",
    "note":null,
    "orderNo":17,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2018-01-09 14:07:22",
    "creator":"admin",
    "updateTime":"2018-01-09 14:07:22",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa60c0561b0160d987c87200a7",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"工地流程",
    "code":"CSHR",
    "frontShow":null,
    "shortName":"GDKQ",
    "note":null,
    "orderNo":15,
    "companyId":"0001K310000000008TK6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2018-01-08 11:50:04",
    "creator":"admin",
    "updateTime":"2020-11-03 18:53:46",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa60c0561b0160d3e3b9b10028",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"发文管理",
    "code":"115",
    "frontShow":1,
    "shortName":"FWGL",
    "note":null,
    "orderNo":14,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2017-12-21 17:14:05",
    "creator":"admin",
    "updateTime":"2020-06-19 17:13:02",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa6077a97d01607859e3a00002",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"工管流程",
    "code":"113",
    "frontShow":null,
    "shortName":"GG",
    "note":null,
    "orderNo":13,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2017-11-28 12:39:23",
    "creator":"admin",
    "updateTime":"2020-06-19 17:12:57",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa5fec0ffb016000ec21c6003d",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"SRM流程",
    "code":"112",
    "frontShow":null,
    "shortName":"SRM",
    "note":null,
    "orderNo":10,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2017-10-31 15:21:50",
    "creator":"admin",
    "updateTime":"2020-06-19 17:12:51",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa5f7067f5015f714ecbad0003",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"PMS流程",
    "code":"111",
    "frontShow":null,
    "shortName":"PMS",
    "note":null,
    "orderNo":9,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2017-09-21 09:10:59",
    "creator":"admin",
    "updateTime":"2020-06-19 17:12:45",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa5e9e0894015ea1fce8260008",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"审计管理",
    "code":"130",
    "frontShow":null,
    "shortName":"SJGL",
    "note":null,
    "orderNo":8,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2017-08-24 20:58:28",
    "creator":"admin",
    "updateTime":"2020-06-19 17:12:40",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa5e145290015e145290220000",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"IT服务",
    "code":"107",
    "frontShow":null,
    "shortName":"IT",
    "note":null,
    "orderNo":7,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2016-11-25 16:23:00",
    "creator":"admin",
    "updateTime":"2020-06-19 17:12:36",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a948c78589a8f4101589a949a130006",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"财务审批",
    "code":"106",
    "frontShow":null,
    "shortName":"CW",
    "note":null,
    "orderNo":6,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2016-11-25 16:22:44",
    "creator":"admin",
    "updateTime":"2020-06-19 17:12:31",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a948c78589a8f4101589a945d5d0005",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"人事审批",
    "code":"105",
    "frontShow":null,
    "shortName":"RS",
    "note":null,
    "orderNo":5,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2016-11-25 16:22:02",
    "creator":"admin",
    "updateTime":"2020-06-19 17:12:25",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a948c78589a8f4101589a93b9b50004",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"行政管理",
    "code":"104",
    "frontShow":null,
    "shortName":"XZGL",
    "note":null,
    "orderNo":4,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2017-09-12 18:13:16",
    "creator":"admin",
    "updateTime":"2021-04-14 21:10:08",
    "updator":"0000001",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa5e758e5d015e759426310008",
    "pid":"8a8a94aa5e758e5d015e75927af40005",
    "name":"合同管理",
    "code":"66",
    "frontShow":1,
    "shortName":"HT",
    "note":null,
    "orderNo":3,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2016-11-25 16:21:41",
    "creator":"admin",
    "updateTime":"2020-06-19 17:12:17",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a948c78589a8f4101589a93659f0003",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"工作管理",
    "code":"103",
    "frontShow":null,
    "shortName":"GZ",
    "note":null,
    "orderNo":3,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2017-09-12 18:12:51",
    "creator":"admin",
    "updateTime":"2020-06-19 17:15:12",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94aa5e758e5d015e7593c2360007",
    "pid":"8a8a94aa5e758e5d015e75927af40005",
    "name":"人事管理",
    "code":"88",
    "frontShow":null,
    "shortName":"HR",
    "note":null,
    "orderNo":2,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2016-11-25 16:21:24",
    "creator":"admin",
    "updateTime":"2020-06-19 17:12:10",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a948c78589a8f4101589a9322790002",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"行政审批",
    "code":"102",
    "frontShow":null,
    "shortName":"XZ",
    "note":null,
    "orderNo":2,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2020-06-15 18:36:56",
    "creator":"admin",
    "updateTime":"2020-08-21 08:33:21",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"40288af472b78daf0172b78dafd10000",
    "pid":"8a8a94aa5e758e5d015e75927af40005",
    "name":"悦云科技",
    "code":"100001",
    "frontShow":null,
    "shortName":"yykj",
    "note":null,
    "orderNo":1,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2016-11-25 16:21:00",
    "creator":"admin",
    "updateTime":"2021-04-24 01:07:44",
    "updator":"0000001",
    "delFlag":1,
    "keyword":null,
    "id":"8a948c78589a8f4101589a92c5b10001",
    "pid":"",
    "name":"通用类型",
    "code":"101",
    "frontShow":1,
    "shortName":"TY",
    "note":null,
    "orderNo":1,
    "companyId":"7401a5e908536545298a7701dbd5c769",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2018-12-27 13:12:05",
    "creator":"admin",
    "updateTime":"2020-06-19 17:16:14",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94ab67eddb240167ee13a9b70003",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"法务管理",
    "code":"8321",
    "frontShow":null,
    "shortName":"FaWuGL",
    "note":null,
    "orderNo":null,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2019-01-03 15:07:06",
    "creator":"admin",
    "updateTime":"2020-06-19 17:11:59",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94ab68127434016812897b3c0015",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"管理改进",
    "code":"8567",
    "frontShow":null,
    "shortName":"GLGJ",
    "note":null,
    "orderNo":null,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  },
  {
    "createTime":"2019-01-23 11:34:49",
    "creator":"00009179",
    "updateTime":"2020-06-19 17:12:05",
    "updator":"admin",
    "delFlag":1,
    "keyword":null,
    "id":"8a8a94ab6878c5d4016878c64ebf0001",
    "pid":"8a948c78589a8f4101589a92c5b10001",
    "name":"合同管理",
    "code":"321",
    "frontShow":null,
    "shortName":"htgl",
    "note":null,
    "orderNo":null,
    "companyId":"ding328e73cb3574de1c35c2f4657eb6",
    "createTimeStr":null,
    "updateTimeStr":null,
    "cname":null
  }
];


export default [
  // mock user login
  {
    url: '/basic-api/getCategories',
    timeout: 200,
    method: 'get',
    response: ({ body }) => {
      const { username, password } = body;
      const checkUser = createFakeUserList().find(
        (item) => item.username === username && password === item.password
      );
      if (!checkUser) {
        return resultError('Incorrect account or password！');
      }
      const { userId, username: _username, token, realName, desc, roles } = checkUser;
      return resultSuccess({
        roles,
        userId,
        username: _username,
        token,
        realName,
        desc,
      });
    },
  },
  {
    url: '/basic-api/getUserInfoById',
    method: 'get',
    response: ({ query }) => {
      const { userId } = query;
      const checkUser = createFakeUserList().find((item) => item.userId === userId);
      if (!checkUser) {
        return resultError('The corresponding user information was not obtained!');
      }
      return resultSuccess(checkUser);
    },
  },
  {
    url: '/basic-api/getPermCodeByUserId',
    timeout: 200,
    method: 'get',
    response: ({ query }) => {
      const { userId } = query;
      if (!userId) {
        return resultError('userId is not null!');
      }
      const codeList = fakeCodeList[userId];

      return resultSuccess(codeList);
    },
  },
] as MockMethod[];
